/**
 * @file bull_hal_sys_semaphore.h
 * @brief 
 * @author yejing (yejh@gongniu.cn)
 * @version 1.0
 * @date 2024-05-09
 * 
 * Copyright 2021-2023 GongNiu Inc. All Rights Reserved.
 * 
 */



#ifndef __BULL_HAL_SYS_SEMAPHORE_H__
#define __BULL_HAL_SYS_SEMAPHORE_H__

#include "bull_hal_adapter.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief  用于创建并初始化semaphore
 * 
 * @param[out] *pHandle semaphore句柄
 * @param[in] init_semCnt  创建信号量时分配给信号量的计数值
 * @param[in] sem_max 可以达到的最大计数值
 * @return int 0=成功，非0=失败
 */
int bull_hal_sys_semaphore_create(SEM_HANDLE *semHandle, const uint32_t init_semCnt, const uint32_t sem_max);


/**
 * @brief bull_hal_sys_semaphore_wait 用于wait semaphore
 * 
 * @param[in] semHandle semaphore句柄
 * @return int 0=成功，非0=失败
 */
int bull_hal_sys_semaphore_wait( IN const SEM_HANDLE semHandle);


/**
 * @brief bull_hal_sys_semaphore_waittimeout used fo wait semaphore with timeout
 *
 * @param[in] semHandle semaphore句柄
 * @param[in] timeout  semaphore超时时间
 * @return int 0=成功，非0=失败
*/
int bull_hal_sys_semaphore_wait_timeout(IN const SEM_HANDLE semHandle, uint32_t timeout);



/**
 * @brief bull_hal_sys_semaphore_post用于post semaphore
 * 
 * @param[in] semHandle semaphore句柄
 * @return int 0=成功，非0=失败
 */
int bull_hal_sys_semaphore_post( IN const SEM_HANDLE semHandle);


/**
 * @brief bull_hal_sys_semaphore_release 用于release semaphore
 * 
 * @param[in] semHandle 
 * @return int 0=成功，非0=失败
 */
int bull_hal_sys_semaphore_delete( IN const SEM_HANDLE semHandle);



#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif